﻿using Common.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Common.Exceptions
{
    /// <summary>
    /// 通用业务异常
    /// 业务异常类，用于在服务层抛出业务相关的异常
    /// 继承自Exception，包含HTTP状态码和业务状态码
    /// </summary>
    public class BusinessException : Exception
    {
        public HttpStatusCode StatusCode { get; }
        public int BusinessCode { get; }

        // 🎯 添加接收 BusinessErrorCode 枚举的构造函数
        public BusinessException(string message, BusinessErrorCode errorCode, HttpStatusCode statusCode = HttpStatusCode.BadRequest)
            : base(message)
        {
            BusinessCode = (int)errorCode;  // 将枚举转换为对应的整数值
            StatusCode = statusCode;
        }

        // 其他现有构造函数保持不变
        public BusinessException(string message, int businessCode = 400, HttpStatusCode statusCode = HttpStatusCode.BadRequest)
            : base(message)
        {
            BusinessCode = businessCode;
            StatusCode = statusCode;
        }

        public BusinessException(string message, HttpStatusCode statusCode)
            : base(message)
        {
            StatusCode = statusCode;
            BusinessCode = (int)statusCode;
        }

        public BusinessException(string message, Exception innerException, int businessCode, HttpStatusCode statusCode)
            : base(message, innerException)
        {
            BusinessCode = businessCode;
            StatusCode = statusCode;
        }

    }
}
